import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.util.HashMap;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

public class Register extends JFrame implements ActionListener
{
	// ������Ҫ�����
    private JButton btn_register;//��ť
    private JTextField ID_text;//�ı���
    private JTextField password_text;//�����

	public Register()
	{
		// �������Ե�����
        setTitle("ע��");// ���ڱ���
        setSize(300, 180);// ���ڴ�С
        setLocationRelativeTo(null);// ���ھ���
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);// �رմ������˳������
        setLayout(new FlowLayout());// ���ò�����ʽ����

        JPanel jp = new JPanel(new GridLayout(4, 1));// �������Ϊ��񲼾�4��1��
        // ��һ��
        JPanel jp1 = new JPanel();
        JLabel id_label = new JLabel("�˺� ");
        ID_text = new JTextField(12);
        jp1.add(id_label);
        jp1.add(ID_text);
        jp.add(jp1);
        // �ڶ���
        JPanel jp2 = new JPanel();
        JLabel password_label = new JLabel("���� ");
        password_text = new JTextField(12);
        jp2.add(password_label);
        jp2.add(password_text);
        jp.add(jp2);
        // ������
        JPanel jp3 = new JPanel();
        btn_register = new JButton("ע��");
        btn_register.addActionListener(this);      //����ע�ᰴť
        jp3.add(btn_register);
        jp.add(jp3);
        // ������
        JPanel jp4 = new JPanel();
        jp.add(jp4);

        add(jp);
	}

	public static void main(String[] args)
	{
	}

	@Override
	public void actionPerformed(ActionEvent e)
	{
	 	String cmd = e.getActionCommand();
	 	if(cmd.equals("ע��"))
	 	{
	 		Database db = new Database("chatdata");
	 		HashMap map = new HashMap();
	 		map.put("id", ID_text.getText());
	 		map.put("password", password_text.getText());
	 		boolean isInsert = db.insert("user_info", map);
	 		if(isInsert)
	 		{
	 			this.dispose();
	 			JOptionPane.showMessageDialog(null, "ע��ɹ�","��ʾ",JOptionPane.WARNING_MESSAGE);
	 		}
	 	}
	}

}
